package ejb;

import com.sleepycat.dbxml.XmlContainer;
import com.sleepycat.dbxml.XmlDocument;
import com.sleepycat.dbxml.XmlException;
import com.sleepycat.dbxml.XmlManager;
import com.sleepycat.dbxml.XmlQueryContext;
import com.sleepycat.dbxml.XmlQueryExpression;
import com.sleepycat.dbxml.XmlResults;
import com.sleepycat.dbxml.XmlValue;
//import com.sleepycat.dbxml.*;

class doDBxml {

    public static void main(String args[]) throws Throwable {
        XmlContainer myContainer = null;
        XmlManager myManager = null;
        //String theContainer = "phone.dbxml";
        String name = "#praded";
        String theContainer = "svg2404.dbxml";
        // Open an XmlManager and an XmlContainer.
        try {
            myManager = new XmlManager();
            //System.out.println(theContainer);
            myContainer =
                    myManager.openContainer(theContainer);

            //myManager.renameContainer("phone.dbxml", "phone2.dbxml");
            if (myContainer == null) {
                System.out.println("nic");
            } else {
                System.out.println("neco");
            }
            //System.out.println(myContainer);

            myContainer = myManager.openContainer(theContainer);
            System.out.println("E");
            System.out.println(myContainer.getPageSize());
            System.out.println("F");
            String myQueryDefault = "for $a in collection('svg2404.dbxml') return dbxml:metadata('dbxml:name', $a)";

            String myQueryBest = "for $a in collection('svg2404.dbxml') "
                    + "where "
                    //+ "$a//*/@rdf:ID [contains(., swana)]"
                    + "contains($a//*/@rdf:ID,'ands')"
                    + " return dbxml:metadata('dbxml:name', $a)";
            String myQuery = "listIndexes";
            XmlQueryContext context = myManager.createQueryContext();
            //context.setBaseURI("http://www.w3.org/1999/02/22-rdf-syntax-ns#");
            //context.setNamespace("rdf","http://www.w3.org/1999/02/22-rdf-syntax-ns#");
            XmlQueryExpression qe = myManager.prepare(myQuery, context);
            XmlResults results = qe.execute(context);

            System.out.println("A" + results + "B");
            //String docString = "<phonebook><name><first>Jan</first><last>Pavlicek</last></name><phone type=home>420-203-2082</phone></phonebook>";
            //myContainer.putDocument(theContainer, docString);
            //myContainer.com.sleepycat.dbxml.XmlUpdateContext.putDocument("neco", docString, null);


            String message = null;
            XmlValue value = results.next();
            while (value != null) {
                //XmlDocument theDoc = value.asDocument();
                //String docName = theDoc.getName();

                String docString = value.asString();
                System.out.println(docString);
                //message = "Document ";
                //message += theDoc.getName() + ":\n";
                //message = value.asString();
                //message += "===============================\n";                
                //System.out.println(message);               
                value = results.next();
            }
        } catch (XmlException e) {
            // Error handling goes here
        } finally {
            myContainer.close();
            System.out.println("closed");
        }

    }
}
